package com.qfedu.microcoupon.template.controller;

import com.qfedu.common.core.annotation.NoLogin;
import com.qfedu.common.core.common.R;
import com.qfedu.common.xxljob.dto.XxlJobInfoDTO;
import com.qfedu.common.xxljob.utils.XxlJobUtil;
import com.qfedu.microcoupon.template.param.CouponTemplateParam;
import com.qfedu.microcoupon.template.service.CouponTemplateService;
import com.qfedu.microcoupon.template.vo.CouponTemplateVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Classname CouponTemplateController
 * @Description TODO
 * @Date 2025-09-25 11:14
 * @Created by 老任与码
 */
@RestController
@RequestMapping("/api/coupon/template")
public class CouponTemplateController {

    @Resource
    private CouponTemplateService couponTemplateService;

    @Resource
    private XxlJobUtil xxlJobUtil;

    @NoLogin
    @PostMapping("/add")
    public R addTemplate(@RequestBody CouponTemplateParam couponTemplateParam) {
        couponTemplateService.addTemplate(couponTemplateParam);
        return R.success();
    }

    /**
     * 返回主动领取的优惠券模版
     *
     * @return
     */
    @GetMapping("/get")
    public R getTemplate() {
        List<CouponTemplateVO> templates = couponTemplateService.getTemplate();
        return R.success(templates);
    }

    @NoLogin
    @PostMapping("/job/test")
    public R addJob(@RequestBody XxlJobInfoDTO xxlJobInfoDTO) {
        // xxlJobUtil.add(xxlJobInfoDTO);
        xxlJobUtil.addAndStart(xxlJobInfoDTO);
        return R.success();
    }
}
